<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>定义子命名空间</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="language.namespaces.definition.html">定义命名空间</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="language.namespaces.definitionmultiple.html">在同一个文件中定义多个命名空间</a></div>
 <div class="up"><a href="language.namespaces.html">命名空间</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="language.namespaces.nested" class="sect1">
  <h2 class="title">定义子命名空间</h2>
  <p class="para">
   与目录和文件的关系很象，PHP
   命名空间也允许指定层次化的命名空间的名称。因此，命名空间的名字可以使用分层次的方式定义：
   <div class="example" id="example-232">
    <p><strong>Example #1 声明分层次的单个命名空间</strong></p>
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">namespace&nbsp;</span><span style="color: #0000BB">MyProject</span><span style="color: #007700">\</span><span style="color: #0000BB">Sub</span><span style="color: #007700">\</span><span style="color: #0000BB">Level</span><span style="color: #007700">;<br /><br />const&nbsp;</span><span style="color: #0000BB">CONNECT_OK&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />class&nbsp;</span><span style="color: #0000BB">Connection&nbsp;</span><span style="color: #007700">{&nbsp;</span><span style="color: #FF8000">/*&nbsp;...&nbsp;*/&nbsp;</span><span style="color: #007700">}<br />function&nbsp;</span><span style="color: #0000BB">connect</span><span style="color: #007700">()&nbsp;{&nbsp;</span><span style="color: #FF8000">/*&nbsp;...&nbsp;*/&nbsp;&nbsp;</span><span style="color: #007700">}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   上面的例子创建了常量<em>MyProject\Sub\Level\CONNECT_OK</em>，类
   <em>MyProject\Sub\Level\Connection</em>和函数
   <em>MyProject\Sub\Level\Connection</em>。
  </p>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="language.namespaces.definition.html">定义命名空间</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="language.namespaces.definitionmultiple.html">在同一个文件中定义多个命名空间</a></div>
 <div class="up"><a href="language.namespaces.html">命名空间</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
